package com.jeedcp.gen.controller;

import com.jeedcp.gen.service.SysGeneratorService;
import com.jeedcp.gen.utils.DBUtil;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@RestController
@RequestMapping("/devtools/generate")
public class GenController {

	@Autowired
	private SysGeneratorService sysGeneratorService;
	@RequestMapping(value = "/initSql")
	public String install() throws Exception {
		DBUtil.runSqlByScriptRunner("sql/mysql.sql");
		return "初始化数据表成功";
	}
	/**
	 * 生成代码
	 */
	@RequestMapping("/code")
	public String code(String tables,String templateName) throws Exception {
		 sysGeneratorService.generatorCode(tables.split(","),templateName);
	     return "success";
	}

}
